<!DOCTYPE html>
<html lang = "pt-BR">
    <head>
        <?php
        session_start();
        include_once'bloco/head.php';
        include_once '../control/conexao.php';
        include_once '../control/valida_sessao.php';

        function __autoload($classe) {
            include_once"../model/{$classe}.class.php";
        }
        ?>
        <link href="bootstrap/css/morris.css" rel="stylesheet">
    </head>
    <body>      
        <div id="wrapper">
            <?php
            include_once'bloco/navbar.php';
            include_once '../control/valida_perfil.php';
            ?>
            <div id="page-wrapper">
                <?php include_once 'bloco/banner.php'; ?>                  
                <div class="row">
                    <div class=" panel panel-success">
                        <div class="panel-heading">
                            <p class="panel-title"><i class = "glyphicon glyphicon-th-large"></i> Lista de Menus</p>
                        </div>
                        <div class="panel-body">
                            <div class="col-lg-12">                                
                                <div class="row">
                                    <div class="col-md-8 col-md-offset-2">                                        
                                        <?php
                                        $menuDAO = new menuDAO();
                                        $arMenu = $menuDAO->listar();
                                        ?>
                                        <div>
                                            <a href="cadastrar_menu.php"><input type="button" class="btn btn-success" value="Novo Menu"></a>
                                        </div><br/>
                                        <table class="table table-responsive table-striped table-condensed table-bordered">
                                            <tr>
                                                <td align="center"><strong>Menu</strong></td>
                                                <td align="center"><strong>Link</strong></td>
                                                <td align="center" colspan="2"><strong>Icone</strong></td>
                                                <td align="center"><strong>Alterar</strong></td>
                                                <td align="center"><strong>Excluir</strong></td>
                                            </tr>
                                            <?php for ($c = 0; count($arMenu) > $c; $c++) { ?>
                                                <tr>
                                                    <td align="center"><?php echo utf8_encode($arMenu[$c]->menu_nome) ?></td>
                                                    <td align="center"><?php echo utf8_encode($arMenu[$c]->menu_link) ?></td>                                                    
                                                    <td align="center"><i class="glyphicon glyphicon-<?php echo utf8_encode($arMenu[$c]->menu_icone) ?>"></i></td>
                                                    <td align="center"><?php echo utf8_encode($arMenu[$c]->menu_icone) ?></td>                                                    
                                                    <td align="center"><a href="editar_menu.php?id=<?php echo utf8_encode($arMenu[$c]->id_menu) ?>"><i class="glyphicon glyphicon-edit"></i></a></td>
                                                    <td align="center"><a onclick="return confirma_menu()" href="../control/excluir_menu.php?id=<?php echo utf8_encode($arMenu[$c]->id_menu) ?>"><i class="glyphicon glyphicon-remove"></i></a></td>
                                                </tr>
                                            <?php } ?>
                                        </table>
                                    </div>
                                </div>                                
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class=" panel panel-success">
                        <div class="panel-heading">
                            <p class="panel-title"><i class = "glyphicon glyphicon-th-large"></i> Lista de Sub-Menus</p>
                        </div>
                        <div class="panel-body">
                            <div class="col-lg-12">                                
                                <div class="row">
                                    <div class="col-md-8 col-md-offset-2">                                        
                                        <?php
                                        $submenuDAO = new submenuDAO();
                                        $arSubMenu = $submenuDAO->listar();
                                        ?>
                                        <div>
                                            <a href="cadastrar_submenu.php"><input type="button" class="btn btn-success" value="Novo Sub-Menu"></a>
                                        </div><br/>
                                        <table class="table table-responsive table-striped table-condensed table-bordered">
                                            <tr>
                                                <td align="center"><strong>Sub-Menu</strong></td>
                                                <td align="center"><strong>Menu</strong></td>
                                                <td align="center"><strong>Link</strong></td>
                                                <td align="center" colspan="2"><strong>Icone</strong></td>
                                                <td align="center"><strong>Mostrar</strong></td>
                                                <td align="center"><strong>Alterar</strong></td>
                                                <td align="center"><strong>Excluir</strong></td>
                                            </tr>
                                            <?php
                                            for ($c = 0; count($arSubMenu) > $c; $c++) {
                                                $menuDAO = new menuDAO();
                                                $Menu = $menuDAO->listar_por_submenu($arSubMenu[$c]->id_menu);
                                                ?>
                                                <tr>
                                                    <td align="center"><?php echo utf8_encode($arSubMenu[$c]->submenu_nome) ?></td>
                                                    <td align="center"><?php echo utf8_encode($Menu->menu_nome) ?></td>
                                                    <td align="center"><?php echo utf8_encode($arSubMenu[$c]->submenu_link) ?></td>
                                                    <td align="center"><i class="glyphicon glyphicon-<?php echo utf8_encode($arSubMenu[$c]->submenu_icone) ?>"></i></td>
                                                    <td align="center"><?php echo utf8_encode($arSubMenu[$c]->submenu_icone) ?></td> 
                                                    <?php if ($arSubMenu[$c]->submenu_show == 1) { ?>
                                                        <td align="center">SIM</td>  
                                                    <?php } else { ?>
                                                        <td align="center">NÃO</td>
                                                    <?php } ?>
                                                    <td align="center"><a href="editar_submenu.php?id=<?php echo utf8_encode($arSubMenu[$c]->id_submenu) ?>"><i class="glyphicon glyphicon-edit"></i></a></td>                                                    
                                                    <td align="center"><a onclick="return confirma_submenu()" href="../control/excluir_submenu.php?id=<?php echo utf8_encode($arSubMenu[$c]->id_submenu) ?>"><i class="glyphicon glyphicon-remove"></i></a></td>                                                    
                                                </tr>
                                            <?php } ?>
                                        </table>
                                    </div>
                                </div>                                
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php
        include_once'bloco/scripts.php';
        ?>
        <script type="text/javascript">
            function confirma_menu() {
                var opcao = confirm("Excluir este Menu?");
                if (opcao == false) {
                    return false
                    exit();
                }
            }
            function confirma_submenu() {
                var opcao = confirm("Excluir este Sub-Menu?");
                if (opcao == false) {
                    return false
                    exit();
                }
            }
        </script>
    </body>
</html>